package cn.im;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class ListDemo {

    private static String[] strArray = new String[2];

    static {
        strArray[0]="hello";
        strArray[1]="world";
    }
    /**
     * 数组转list
     */
    @Test
    public void array2List(){
        //使用Arrays.asList转换，对转换后的list，只能查改，增删报错
        List list =  Arrays.asList(strArray);
        System.out.println("Arrays.asList: "+list);
//        list.add("1");

        //构建器创建，可增删改查
        ArrayList<String> list1 = new ArrayList<String>(list);
        System.out.println("new ArrayList<String>(list): "+list1);

        //工具类复制，可增删改查
        ArrayList<String> list2 = new ArrayList<String>(strArray.length);
        Collections.addAll(list2,strArray);
        System.out.println("Collections.addAll: "+list2);

    }
}
